<?php
require_once 'init.php';
if(!$sessionID){
	header('location:login.php');
}
$id = isset($_GET['id'])?$_GET['id']:0;
$action = isset($_GET['action'])?$_GET['action']:'';
$albumID = isset($_GET['albumID'])?$_GET['albumID']:0;

if($action==''||(!in_array($action,array('home','wedding','studio','cooperation','guest')))){
	header('index.php');
}
if($action!='home'&&$albumID==0){
	header('location:img.php?action='.$action);
}
if($id==0){
	header('location:img.php?action='.$action);
}
$xml = simplexml_load_file($contentDB);
$children = $xml->children();
$content = $children[1];
$page = $content->children();
$imageSrc = '';
if($action=='home'){
	$photo = $page[0];
	$images = $photo->children();
	foreach($images->children() as $img){
		$attrs = $img->attributes();
		if((int)$attrs['id'] == $id){
			$imageSrc = (string)$img;
		}
	}
}else{
//elseif($action=='wedding'){
	if($action=='wedding'){
		$photo = $page[2];
	}elseif($action=='studio'){
		$photo = $page[3];
	}elseif($action=='cooperation'){
		$photo = $page[4];
	}elseif($action=='guest'){
		$photo = $page[5];
	}
	foreach($photo->children() as $item){
		$attr = $item->attributes();
		if($attr['id']==$albumID){
			foreach($item->children() as $img){
				$attrs = $img->attributes();
				if((int)$attr['id']==$id){
					$imageSrc = (string)$img;
				}
			}	
		}
	}
}



?>
<html>
<head>
	<meta charset="utf-8" />
	<link rel="stylesheet" href="<?php echo $host;?>/manager/css/default.css" />
</head>
<body>
	<div class="header"></div>
	<div class="middle">
		<div class="left">
			<?php require_once 'left.php';?>		
		</div>
		<div class="right">
			<form action="imgSave.php" method="post" />
			<table class="imageTable">
				<tr>
					<td>图片</th>
					<td><img class="imageSrc" src="<?php echo '/'.$imageSrc;?>" width="100" height="100" /></td>
				</tr>
				<tr>
					<td colspan="2">
						<input type="file" name="file_upload" id="file_upload" />
					</td>
				</tr>
				<tr>
					<td colspan="2"><input type="submit" value="保存" /></td>
				</tr>
			</table>
			<input type="hidden" name="id" value="<?php echo $id;?>" />
			<input type="hidden" name="src" class="postSrc" value="<?php echo $imageSrc;?>" />
			<input type="hidden" name="action" value="<?php echo $action;?>" />
			<input type="hidden" name="albumID" value="<?php echo $albumID;?>" />
			</form>
	</div>
	</div>
	<div class="footer">
	</div>
<script type="text/javascript" src="/manager/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/manager/js/uploadify/jquery.uploadify-3.1.min.js"></script>
<script type="text/javascript">
$(function() {
	$("#file_upload").uploadify({
		'swf'      : '/manager/js/uploadify/uploadify.swf',
		'uploader' : '/manager/uploadify.php',
		'queueSizeLimit':1,
		'onUploadSuccess':function(file,data,response){
			$(".imageSrc").attr('src','/'+data);
			$(".postSrc").val(data);
		}
	});
});
</script>
</body>
</html>
